package com.batchengine.manager;

import com.batchengine.pool.WorkerPool;
import com.batchengine.schedular.CronSchedularWorkerManager;
import static com.batchengine.schedular.CronSchedularWorkerManager.getCronSchedular;
import com.batchengine.worker.ScheduledTask;

import java.util.Map;

/**
 * Created by  solutions
 * Author: sunil.incubator@yahoo.com
 * Date: Jul 25, 2009
 */
public abstract class ScheduledWorkerManager extends WorkerManager {

    protected ScheduledWorkerManager(String name) {
        super(name);
    }

    public abstract Map<Long, ScheduledTask> getAllScheduledTasks();

    @Override
    protected void init() {
        CronSchedularWorkerManager schedularWorkerManager = getCronSchedular();
        schedularWorkerManager.startSchedular();
    }

    public void cleanUpTask(Long taskId) {
        ScheduledTask scheduledTask = getAllScheduledTasks().get(taskId);
        WorkerPool pool = scheduledTask.getWorkerPool();
        pool.stopWorkers();
        removeWorkerPool(pool);
    }
}